/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.entity.repository;

import canteen.sys.model.entity.BillMaster;
import canteen.sys.model.generic.GenericHibernateDAOSupport;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author TNT
 */
public class BillMasterDAOImpl extends GenericHibernateDAOSupport<BillMaster, Long> implements BillMasterDAO {

    @Override
    public List<BillMaster> findAllBillSearchByUserId(int userId) {
        List<BillMaster> listBill = null;
        Transaction transaction = getSession().beginTransaction();
        try {
            listBill = getSession().createCriteria(BillMaster.class)
                    .add(Restrictions.eq("loginMaster.lId", userId)).list();
            transaction.commit();
        } catch (HibernateException ex) {
            transaction.rollback();
        }
        return listBill;
    }

    @Override
    public List<BillMaster> findAllBillByDepartmentId(int departmentId) {
        List<BillMaster> listBill = null;
        Transaction transaction = getSession().beginTransaction();
        try {
            listBill = getSession().createCriteria(BillMaster.class)
                    .add(Restrictions.eq("department.deptId", departmentId)).list();
            transaction.commit();
        } catch (HibernateException ex) {
            transaction.rollback();
        }
        return listBill;
    }
}
